//package com.ftg.youx.client;
//
//import com.alibaba.fastjson2.JSON;
//import com.ftg.youx.entity.SysEmp;
//import com.ftg.youx.service.SysEmpService;
//import com.ftg.youx.util.MqUtil;
//import com.rabbitmq.client.Channel;
//import com.rabbitmq.client.Connection;
//import com.rabbitmq.client.ConnectionFactory;
//import com.rabbitmq.client.DeliverCallback;
//import lombok.SneakyThrows;
//import org.apache.catalina.core.ApplicationContext;
//import org.springframework.beans.factory.BeanFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationEvent;
//import org.springframework.context.ApplicationListener;
//import org.springframework.context.annotation.AnnotationConfigApplicationContext;
//import org.springframework.context.event.EventListener;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.util.concurrent.TimeoutException;
//
///**
// * 更改成为springboot+rabbitmq
// * mq数据接收客户端
// *      （.. 发布者 - 订阅者
// *          [站内消息]
// *          1 : doc.html String 消息原文
// *          2 : 发送给rabbitmq - exchange [mysql表添加一份]
// *
// *          3 : 原型 - 新的java - exchange - getQueue()
// *      ..）@EnableRabbit
// * @author 布衣
// */
//@Component
//public class MqRevClient implements ApplicationListener {
//
////    public static void main(String[] args) throws IOException, TimeoutException {
////        ConnectionFactory factory = new ConnectionFactory();
////        factory.setHost("localhost");
////        factory.setPort(5672);
////        factory.setVirtualHost("/");
////        factory.setUsername("guest");
////        factory.setPassword("guest");
////        Connection connection = factory.newConnection();
////        //创建频道
////        Channel channel = connection.createChannel();
////        String queueName = "queue01";
////        //创建队列
////        channel.queueDeclare(queueName, false, false, false, null);
////
////        //消费者消费消息
////        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
////            String message = new String(delivery.getBody(), "UTF-8");
////
////            SysEmp sysEmp = JSON.parseObject(message, SysEmp.class);
////
////            AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
////            context.refresh();
////
////            //拿到spring容器里面的类的实例
////            SysEmpService sysEmpService = context.getBean(SysEmpService.class);
////            sysEmpService.save(sysEmp);
////
////        };
////        channel.basicConsume(queueName, true, deliverCallback, consumerTag -> { });
////    }
//
//    @Autowired
//    SysEmpService sysEmpService;
//
//    @SneakyThrows
//    @Override
//   //@RabbitListener
//    public void onApplicationEvent(ApplicationEvent event) {
//        ConnectionFactory factory = new ConnectionFactory();
//        factory.setHost("localhost");
//        factory.setPort(5672);
//        factory.setVirtualHost("/");
//        factory.setUsername("guest");
//        factory.setPassword("guest");
//        Connection connection = factory.newConnection();
//        //创建频道
//        Channel channel = connection.createChannel();
//        String queueName = "queue01";
//        //创建队列
//        channel.queueDeclare(queueName, false, false, false, null);
//
//        //消费者消费消息@RabbitHandler
//        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
//            String message = new String(delivery.getBody(), "UTF-8");
//
//            SysEmp sysEmp = JSON.parseObject(message, SysEmp.class);
//            System.out.println("-->===y");
//            //拿到spring容器里面的类的实例
//            sysEmpService.save(sysEmp);
//
//        };
//        channel.basicConsume(queueName, true, deliverCallback, consumerTag -> { });
//
//        System.out.println("-->===X");
//    }
//}


//java.lang.SecurityException: Attempt to deserialize unauthorized class com.ftg.youx.entity.SysEmp; add allowed class name patterns to the message converter or, if you trust the message orginiator, set environment variable 'SPRING_AMQP_DESERIALIZATION_TRUST_ALL' or system property 'spring.amqp.deserialization.trust.all' to true
//        at org.springframework.amqp.utils.SerializationUtils.checkAllowedList(SerializationUtils.java:165) ~[spring-amqp-3.1.0.jar:3.1.0]